﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ConnectToDatabase;

namespace QLGiayDep.Forms
{
    /// <summary>
    /// Interaction logic for WinThemPhieuTraSanPhamxaml.xaml
    /// </summary>
    public partial class WinThemPhieuTraSanPhamxaml : Window
    {
        private InsertDB insertDB;
        private SetID setId;
        private string URL;

        public WinThemPhieuTraSanPhamxaml()
        {
            InitializeComponent();
        }

        public WinThemPhieuTraSanPhamxaml(string _URL)
        {
            InitializeComponent();
            URL = _URL;
            setId = (SetID)Activator.GetObject(typeof(SetID), URL + "SETID_OBJECT");
            insertDB = (InsertDB)Activator.GetObject(typeof(InsertDB), URL + "INSERTDB_OBJECT");
            txtMaPT.Text = setId.GenerateMaPhieuTra();
        }

        private void bntThemNV_Click(object sender, RoutedEventArgs e)
        {
            DateTime m_dtNgayTra = date_NgayTra.SelectedDate.Value;
            //them phieu tra
            
            int kt;
            kt = insertDB.InsertPhieuTraHang(txtMaPT.Text, m_dtNgayTra.ToString("yyyy/MM/dd"));
            kt = insertDB.InsertCtPhieuTra(txtMaPT.Text, txtMaSP.Text, txtThongTinLoi.Text);
            if (kt == -1)
                MessageBox.Show("Thêm phiếu trả thất bại", "Lỗi");
            else
            {
                MessageBox.Show("Thêm nhà phiếu trả Thành Công", "Thông Báo");
               
                txtMaPT.Text = setId.GenerateMaPhieuTra();
                txtMaSP.Clear();
                txtThongTinLoi.Clear();

            }
        }

        private void bntThoatNV_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
